package xw.qxypt.modules.baseinfo.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import xw.qxypt.common.utils.Constant;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.Query;

import xw.qxypt.modules.baseinfo.dao.LhpHighwaySectionDao;
import xw.qxypt.modules.baseinfo.entity.LhpHighwaySectionEntity;
import xw.qxypt.modules.baseinfo.service.LhpHighwaySectionService;


@Service("lhpHighwaySectionService")
public class LhpHighwaySectionServiceImpl extends ServiceImpl<LhpHighwaySectionDao, LhpHighwaySectionEntity> implements LhpHighwaySectionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String roadName= (String) params.get("roadName");
        IPage<LhpHighwaySectionEntity> page = this.page(
                new Query<LhpHighwaySectionEntity>().getPage(params),
                new QueryWrapper<LhpHighwaySectionEntity>()
                        .like(StringUtils.isNotBlank(roadName),"road_name", roadName)
                        .apply(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
        );

        return new PageUtils(page);
    }

    @Override
    public List<LhpHighwaySectionEntity> waysectTree() {
        List<LhpHighwaySectionEntity> list =this.list(
                new QueryWrapper<LhpHighwaySectionEntity>()
                        .eq(StringUtils.isNotBlank("0"),"is_active", "0")
        );
        return list;
    }

    @Override
    public List<String> findWaysectIdByUser(Long userId) {
        return this.baseMapper.findWaysectIdByUser(userId);
    }

}
